//
//  InsideMapViewController.m
//  YouthOlympic2014
//
//  Created by xiangpaopao on 14-7-3.
//  Copyright (c) 2014年 mitian. All rights reserved.
//

#import "InsideMapViewController.h"

@interface InsideMapViewController ()

@property (nonatomic, strong) UIScrollView *scrollView;
@property (nonatomic, strong) UIImageView *imageView;

@end

@implementation InsideMapViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.title =NSLocalizedString(@"青奥村地图", nil);
    
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth , ScreenHeight -64)];
    
    
    [scrollView setBackgroundColor:[UIColor whiteColor]];
    [scrollView setDelegate:self];
    [scrollView setShowsHorizontalScrollIndicator:NO];
    [scrollView setShowsVerticalScrollIndicator:NO];
    [scrollView setMaximumZoomScale:3.7];
    
    UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"map.jpg"]];
    
    CGRect rect;
    rect.size.width = imageView.image.size.width/4;
    rect.size.height = imageView.image.size.height/4;
    
    [imageView setFrame:rect];
    
    [scrollView setContentSize:[imageView frame].size];
    [scrollView setMinimumZoomScale:[scrollView frame].size.height / [imageView frame].size.height];
    [scrollView setZoomScale:[scrollView minimumZoomScale]];
    
    
    self.scrollView = scrollView;
    self.imageView = imageView;
    
    [self.scrollView addSubview:self.imageView];
    
    [[self view] addSubview:self.scrollView];
    
}


- (void)finishCropping {
	float zoomScale = 1.0 / [self.scrollView zoomScale];
	
	CGRect rect;
	rect.origin.x = [self.scrollView contentOffset].x * zoomScale;
	rect.origin.y = [self.scrollView contentOffset].y * zoomScale;
	rect.size.width = [self.scrollView bounds].size.width * zoomScale;
	rect.size.height = [self.scrollView bounds].size.height * zoomScale;
	
	CGImageRef cr = CGImageCreateWithImageInRect([[self.imageView image] CGImage], rect);
	CGImageRelease(cr);
}

- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView {
	return self.imageView;
}


@end
